package com.vividstores.integration.mq;

import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.apache.commons.beanutils.BeanUtils;

import com.vividstores.integration.mq.impl.MQFileSenderImpl;

public class SendFileLauncher {

	public static void main(String[] args) {
		try {
			Properties properties = new Properties();
			properties.load(ClassLoader.getSystemResourceAsStream("mq.send.properties"));
			
			MQFileSenderImpl fileSender = new MQFileSenderImpl();
			BeanUtils.populate(fileSender, properties);		//设置MQFileSender的Queue连接信息
			
			MQFileBundle fileBundle = new MQFileBundle();
			
			MQFileBundleHeader header = new MQFileBundleHeader();
			header.setType(MQFileBundleType.Design);
			header.setVersion("1.0");
			header.setSendTime(Calendar.getInstance().getTime());
			Map<String, String> headExtension = new HashMap<String, String>();
			headExtension.put("HEAD_PARAM_1", "HEAD_PARAM_VALUE_1");
			headExtension.put("HEAD_PARAM_2", "HEAD_PARAM_VALUE_2");
			header.setData(headExtension);
			header.setDescription("sample description");
			
			List<MQFile> files = new ArrayList<MQFile>();
			
			File file1 = new File("D:\\projects\\BnQ\\References\\精通WebSphere MQ.pdf");
			MQFile mqFile1 = new MQFile();
			//对发送方只需设置MQFile.setFile和MQFile.setType信息，其他属性在发送文件过程中由API自动填充
			mqFile1.setFile(file1);
			mqFile1.setType(MQFileType.Document);
			Map<String, String> fileExtension1 = new HashMap<String, String>();
			fileExtension1.put("FILE_PARAM_1", "FILE_PARAM_VALUE_1");
			fileExtension1.put("FILE_PARAM_2", "FILE_PARAM_VALUE_2");
			//设置业务字段，开放式数据结构，需要应用程序双方协商传输的内容
			mqFile1.setData(fileExtension1);
			files.add(mqFile1);
			
			File file2 = new File("D:\\projects\\BnQ\\References\\SAP开发概览v1.1From苏宁.ppt");
			MQFile mqFile2 = new MQFile();
			//对发送方只需设置MQFile.setFile和MQFile.setType信息，其他属性在发送文件过程中由API自动填充
			mqFile2.setFile(file2);
			mqFile2.setType(MQFileType.Rendering);
			Map<String, String> fileExtension2 = new HashMap<String, String>();
			fileExtension2.put("FILE_PARAM_3", "FILE_PARAM_VALUE_3");
			fileExtension2.put("FILE_PARAM_4", "FILE_PARAM_VALUE_4");
			//设置业务字段，开放式数据结构，需要应用程序双方协商传输的内容
			mqFile2.setData(fileExtension2);
			files.add(mqFile2);
			
			fileBundle.setHeader(header);
			fileBundle.setFiles(files);

			//调用该方法发送文件传输请求
			fileSender.send(fileBundle);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
